package com.gzyj.jtt808.v2011.protocol.terminalparam;

import com.gzyj.jtt808.utils.HexBytesUtil;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;

/**
 * UDP 消息重传次数
 *
 * @author lhj
 */
@Data
public class JTT808_0x8103_0x0005 extends JTT808_0x8103_TerminalParam implements Serializable {

    private int ParamValue;//UDP 消息重传次数

    public JTT808_0x8103_0x0005() {
        super(0x0005);
        this.setParamLength(4);
    }

    @Override
    public void encode(ByteBuf buf) {
        buf.writeInt(this.getParamId());
        buf.writeByte(this.getParamLength());
        buf.writeInt(this.ParamValue);
    }

    @Override
    public JTT808_0x8103_0x0005 decode(ByteBuf buf) {
        byte[] temp = HexBytesUtil.readByOffset(buf, 4);
        this.setParamId(HexBytesUtil.byteArrayToInt(temp));
        temp = HexBytesUtil.readByOffset(buf, 1);
        this.setParamLength(Byte.toUnsignedInt(temp[0]));
        temp = HexBytesUtil.readByOffset(buf, 4);
        this.ParamValue = HexBytesUtil.byteArrayToInt(temp);
        return this;
    }
}